/*
*    Phantom Test Driver v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/*
 * PTDRegister.java
 *
 * Created on June 29, 2007, 10:42 AM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package ptd;

/**
 *
 * @author John
 */
public class PTDRegister {
    
    private int Type;
    
    /** Creates a new instance of PTDRegister */
    public PTDRegister() {
        Type = 100;
    }
    
    public int StringToIntBase36(String In){
        int len = In.length();
        int Res = 0;
        byte[] b = In.getBytes();
        int i = 0;
        String zero = "0";
        byte[] b0 = zero.getBytes();
        int m = 1;
        for(i = len-1; i >= 0; i--){
            int qq = len - 1 - i;
            if(b[i] > 57){
                Res = Res + (b[i] - b0[0] - 7)*m;
            }else{
                Res = Res + (b[i] - b0[0])*m; //(b[i] - b0[0])*36^qq;
            }
            m = m * 36; // why we cant just do 36^qq is beyond me...
        }
        
        return Res;
    } 
    
    public boolean CheckKey(String Key){
        return true;
        /*
        int len = 0;
        int RandNum = 0;
        int KeyNum = 0;
        
        char[] KeyBuff = new char[6];
        char[] RandBuff = new char[4];;
                
        len = Key.length();
        if(len != 10) return false;

        KeyBuff[5]  = Key.charAt(0);
        RandBuff[3] = Key.charAt(1);
        KeyBuff[1]  = Key.charAt(2);
        RandBuff[2] = Key.charAt(3);
        KeyBuff[3]  = Key.charAt(4);
        KeyBuff[0]  = Key.charAt(5);
        RandBuff[1] = Key.charAt(6);
        KeyBuff[4]  = Key.charAt(7);
        RandBuff[0] = Key.charAt(8);
        KeyBuff[2]  = Key.charAt(9);
        
        String sKeyBuff = new String(KeyBuff);
        String sRandBuff = new String(RandBuff);
                        
        RandNum = StringToIntBase36(sRandBuff);
        KeyNum = StringToIntBase36(sKeyBuff);
        
        KeyNum = KeyNum + 202;
	KeyNum = KeyNum / 32;
	KeyNum = KeyNum - Type;
	KeyNum = KeyNum / 2;

	if(KeyNum == RandNum)
	{
		return true;
	}
	return false;
        
/*        
        int len = 0;
	int RandNum = 0;
	int KeyNum = 0;
	char RandBuff[5];
	char KeyBuff[7];
	len = strlen(Key);
	if(len != 10) return false;
	strlwr(Key);
	sscanf(Key, "%c%c%c%c%c%c%c%c%c%c", &KeyBuff[5], &RandBuff[3], &KeyBuff[1], &RandBuff[2], &KeyBuff[3], &KeyBuff[0], &RandBuff[1], &KeyBuff[4], &RandBuff[0], &KeyBuff[2]);
	strupr(Key);
	RandBuff[4] = 0;
	KeyBuff[6] = 0;

	RandNum = (int)strtoul(RandBuff, 0, 36);
	KeyNum = (int)strtoul(KeyBuff, 0, 36);

	KeyNum = KeyNum + 202;
	KeyNum = KeyNum / 32;
	KeyNum = KeyNum - Type;
	KeyNum = KeyNum / 2;

	if(KeyNum == RandNum)
	{
		return true;
	}
	return false;
 */

    }
    
}
